package com.ipan.poi.utils;

/**
 * 字符串工具类
 * 
 * @author iPan
 * @version 2013-9-20
 */
public class PoiStringHelper extends org.apache.commons.lang.StringUtils {

	public static final String EOL = System.getProperty("line.separator");

	/**
	 * 填充null为空字符串
	 */
	public static String convertNull(String text) {
		return (text != null) ? text : "";
	}

	/**
	 * 包路径的类名 -> 类名
	 */
	public static String unqualify(String qualifiedName) {
		int loc = qualifiedName.lastIndexOf(".");
		return (loc < 0) ? qualifiedName : qualifiedName.substring(loc + 1);
	}

	/**
	 * 包路径的类名 -> 包路径
	 */
	public static String qualifier(String qualifiedName) {
		int loc = qualifiedName.lastIndexOf(".");
		return (loc < 0) ? "" : qualifiedName.substring(0, loc);
	}

	/**
	 * 前缀+类名=包路径的类名
	 */
	public static String qualify(String prefix, String name) {
		if (name == null || prefix == null) {
			throw new NullPointerException();
		}
		return new StringBuffer(prefix.length() + name.length() + 1).append(prefix).append('.').append(name).toString();
	}
	
	/**
	 * 首字母变大写
	 */
	public static String firstCharToUpperCase(String str) {
		char firstChar = str.charAt(0);
		if (firstChar >= 'a' && firstChar <= 'z') {
			char[] arr = str.toCharArray();
			arr[0] -= ('a' - 'A');
			return new String(arr);
		}
		return str;
	}
	
}